package com.frame.auth.security.exception;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.frame.common.tools.result.ResultCode;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;

/**
 * @auther zhangwj
 * @date 2021/3/24 下午5:22
 */
@JsonSerialize(using = AuthExceptionSerializer.class)
public class AuthException extends OAuth2Exception {

    public static AuthException getAuthException(ResultCode resultCode) {
        return new AuthException(resultCode.getCode(), resultCode.getContent());
    }

    /**
     * 错误码
     */
    private String errCode;

    /**
     * 错误描述
     */
    private String errMsg;

    private Object payload;

    /**
     * isSucceed
     *
     * @return boolean
     */
    public boolean isSucceed() {
        return ResultCode.SUCCESS.getCode().equals(this.errCode);
    }

    public AuthException(String errCode, String errMsg) {
        super(errMsg);
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public AuthException(String msg) {
        super(msg);
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public Object getPayload() {
        return payload;
    }

    public void setPayload(Object payload) {
        this.payload = payload;
    }
}
